package com.csaba.connector.bha;

import java.util.logging.Logger;

import com.csaba.connector.DummyServer;
import com.csaba.connector.ServiceException;
import com.csaba.connector.bha.model.BHASession;
import com.csaba.connector.model.Session;
import com.csaba.connector.service.AbstractBankService;
import com.csaba.connector.service.LogoutService;
import com.csaba.util.LoggerHelper;
import com.ind.simplenode.SimpleNode;

public class BHALogoutService extends AbstractBankService implements LogoutService
{
	private final static Logger logger = LoggerHelper.getDefaultLogger();

	@Override
	public void execute( final Session session ) throws ServiceException
	{
		final BHASession local = (BHASession) session;
		DummyServer.getInstance().removeSession(session);

		// Invoke logout, and clear session object. 
		final SimpleNode logoutRequest = new SimpleNode();

		local.sendRequest(null, "logout", logoutRequest, null); //response is dropped. Nothing is expected.

		logger.info("User " + local.getCustomer().getName() + " is logged out...");

		local.invalidateSession();
	}
}
